
<html>

	<head>
            <link rel="stylesheet" type="text/css" href="scripts/prueba.css"/>
	</head>

	<body>
		<div class="pcpal">
                <div class="menu">
                <?php
                    require_once("scripts/Menu.php");
                ?>
                </div>
                <div class="content1">
                    <img src="/AppResiduos2/images/6331380.jpg" alt="energia" style="width: 800px; height: 320px" align="middle">
                </div>
<!--                <div class="content2">-->
                <?php
                require_once("/var/www/AppResiduos2/lib/dao/EmpresaDAO.php");
                require_once("/var/www/AppResiduos2/lib/dao/ResiduoDAO.php");
                require_once("/var/www/AppResiduos2/lib/dao/ConstituyenteResiduoDAO.php");
                require_once("/var/www/AppResiduos2/lib/dao/TransportadorResiduoDAO.php");

                $rDAO = new ResiduoDAO();
                $r = $rDAO->listarResiduos();

                $crDAO = new ConstituyenteResiduoDAO();

                $trDAO = new TransportadorResiduoDAO();

                $pDAO = new EmpresaDAO();
//                $prod = urldecode(serialize($prod));
//                $prod = unserialize(urldecode($prod));

                session_start();
		$privil = $_SESSION['priv'];

                ?>

                <table id="residues" border="1">
				<tr class="alt">
					<td> Id </td>
					<td> Name </td>
                                        <td> Toxicity </td>
                                        <td> Transport </td>
                                        <td> Quantity </td>
                                        <td> Available quantity </td>
                                        <td> Transported quantity </td>
                                        <td> Components </td>
                                        <td> Producer </td>
                                        <td></td>
                                        <td></td>
				</tr>
		<?php
                                        $i = 0;
					while ($i < sizeof($r))
					{

                ?>				<tr class="alt">
							<td> <?php print_r($r[$i]->id); ?> </td>
							<td> <?php print_r($r[$i]->name); ?> </td>
                                                        <td> <?php print_r($r[$i]->toxicity); ?> </td>
                                                        <td> <?php print_r($r[$i]->typetransport); ?> </td>
                                                        <td> <?php print_r($r[$i]->quantity); ?> </td>
                                                        <td> <?php $cantRest = $trDAO->listarCantRestante2($r[$i]->id, $r[$i]->idproducer);
                                                            print_r($cantRest); ?>
                                                        </td>
                                                        <td> <?php $cantTransp = $trDAO->listarCantTransp2($r[$i]->id, $r[$i]->idproducer);
                                                            print_r($cantTransp); ?>
                <?php
                                                        if ($privil == 1)
                                                        {
                ?>
                                                        <a href="ListarResiduosTransportados.php?idResidue=<?php print_r($r[$i]->id); ?>&idproducer=<?php print_r($r[$i]->idproducer); ?>&quantity=<?php print_r($r[$i]->quantity); ?>">Manage</a>
                                                        </td>
                <?php
                                                        }
                ?>
                                                        

                                                        <td> <?php $comp = $crDAO->obtenerNombreConstResiduo($r[$i]->id, $r[$i]->idproducer);
                                                            print_r(implode(",", $comp)); ?>
                <?php
                                                        if ($privil == 1)
                                                        {
                ?>
                                                        <a href="ListarConstituyentes.php?idResidue=<?php print_r($r[$i]->id); ?>&idproducer=<?php print_r($r[$i]->idproducer); ?>">Manage</a>
                                                        </td>
                <?php
                                                        }
                ?>
                                                        <td> <?php
                                                            $prod = $pDAO->obtenerEmpresa($r[$i]->idproducer);
                                                            print_r($prod[0]->name); ?>
                                                        </td>
		<?php

						if ($privil == 1)
						{

                ?>
							<td> <form method=post action="AdministrarResiduo.php">
                                                                <input type="hidden" name="id_residue" value="<?php print_r($r[$i]->id); ?>">
                                                                <input type="hidden" name="id_producer" value="<?php print_r($r[$i]->idproducer); ?>">
								<input type="hidden" name="name_residue" value="<?php print_r($r[$i]->name); ?>">
                                                                <input type="hidden" name="quantity_residue" value="<?php print_r($r[$i]->quantity); ?>">
								<input type="submit" name="modifyResidue" value="Modify"> </form> </td>
							<td> <form method=post action="AdministrarResiduo.php">
                                                                <input type="hidden" name="id_residue" value="<?php print_r($r[$i]->id); ?>">
                                                                <input type="hidden" name="id_producer" value="<?php print_r($r[$i]->idproducer); ?>">
								<input type="hidden" name="name_residue" value="<?php print_r($r[$i]->name); ?>">
								<input type="submit" name="deleteResidue" value="Delete"> </form> </td>

		<?php
						}
                                                $i = $i + 1;
		?>

						</tr>
		<?php
					}
					if ($privil == 1){

		?>
                                                <tr class="alt">
                                                    <td colspan=9></td>
                                                    <td colspan=1>
                                                        <form method=post action="AdministrarResiduo.php">
                                                            <input type="submit" name="newResidue" value="New">
                                                        </form>
                                                    </td>
                                                    <td></td>
						</tr>
		<?php
					}
		?>
		</table>
                </div>
<!--		</div>-->
	</body>



</html>


